const BASE_URL = 'https://api-hmugo-web.itheima.net/api/public/v1';

const get = (url, data,token) => {
	return request(url, data, 'GET',token);
}

const post = (url, data,token) => {
	return request(url, data, 'POST',token);
}

const request = (url, data, method = 'GET',token) => {
	return new Promise((reslove, reject) => {
		uni.request({
			url: BASE_URL + url,
			data,
			method,
			header:{'Authorization': token },
			success: (res) => {
				if (res.data.meta.status !== 200) {
					// toast提示
					uni.showToast({
						title: res.data.meta.msg,
						icon: 'none'
					})
					reject(res.data.meta.msg)
				} else {
					reslove(res.data.message)
				}
				
			}
		})
	})
}

const http = {
	get,
	post
}

export default http;